package springBoot_dzfpxt.custom;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

public class CommonService<T,ID>{
	@Autowired
	private CommonRepository<T, ID> baseDAO;
	
	public List<T> findAll(ID id){
		return baseDAO.findAll();
	}
	
	public T findById(ID id) {
		Optional<T> findById = baseDAO.findById(id);
		if(findById.isPresent()) {//如果不为空
			return findById.get();
		}
		return null;
	}
	
	public void sava(T entity) {
		baseDAO.save(entity);
	}
	
	public void delete(T model) {
		baseDAO.delete(model);
	}
	
	public void deleteById(ID id) {
		baseDAO.deleteById(id);
	}
	
	public List<T> findAll(Sort sort){
		return baseDAO.findAll(sort);
	}
	
	public Page<T> findAll(Pageable pageable) {
		return baseDAO.findAll(pageable);
	}
}
